package com.htudata.core.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.htudata.convention.domain.ResponseResult;

public class ResultGenerator {

  public static ResponseResult genResult(Object data) {
    ResponseResult result = new ResponseResult();
    result.setData(data);
    result.setStatus(0);
    result.setMsg("success");
    result.setSeq("");
    return result;
  }
  
  public static ResponseResult genResult(String code, Object data) {
    ResponseResult result = new ResponseResult();
    result.setData(data);
    result.setStatus(0);
    result.setMsg("success");
    result.setSeq(code);
    return result;
  }
  
  public static JSONObject genResultWithA2Status(ResponseResult responseResult, int a2Code) {
    JSONObject result = (JSONObject)JSON.toJSON(responseResult);
    result.put("a2Code", Integer.valueOf(a2Code));
    return result;
  }
  
  public static ResponseResult genResult(String code, Object data, String msg) {
    ResponseResult result = new ResponseResult();
    result.setData(data);
    result.setStatus(0);
    result.setMsg(msg);
    result.setSeq(code);
    return result;
  }
  
  public static ResponseResult genErrorResult() {
    ResponseResult result = new ResponseResult();
    result.setStatus(500);
    result.setMsg("failure");
    result.setSeq("");
    return result;
  }
  
  public static ResponseResult genErrorResult(String msg) {
    ResponseResult result = new ResponseResult();
    result.setStatus(500);
    result.setMsg(msg);
    result.setSeq("");
    return result;
  }
  
  public static ResponseResult genErrorResult(String code, int status, String msg) {
    ResponseResult result = new ResponseResult();
    result.setSeq(code);
    result.setMsg(msg);
    result.setStatus(status);
    return result;
  }
  
  public static ResponseResult genErrorResult(Throwable throwable) {
    ResponseResult result = new ResponseResult();
    result.setStatus(500);
    result.setMsg(throwable.getMessage());
    result.setSeq("");
    return result;
  }
}
